package Demo;

import java.io.*;

public class Test1 {
    //根据字节流创建
    public static void main(String[] args) {
        OutputStream os=null;
        try{
            os=new FileOutputStream("C:\\java2024\\20241127\\test1.txt");
            os.write(String.valueOf(123).getBytes());
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            if(os!=null){
                try{
                    os.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }

        InputStream is=null;
        try{
            is=new FileInputStream("C:\\java2024\\20241127\\test1.txt");
            int num;
           while((num=is.read())!=-1){
               System.out.println((char)num);
           }
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            if(is!=null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
